package com.ag.utils;

import java.io.IOException;
import java.lang.reflect.Type;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializeWriter;

public class StringConvertJSONArraySerializer implements ObjectSerializer {

	@Override
	public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
			throws IOException {
		SerializeWriter out = serializer.out;
		
		String string = (String) object;
		
		JSONArray array = JSON.parseArray(string);
		if(array == null) {
			out.writeNull();
		} else {
			out.write(array.toJSONString());
		}
		
	}

}
